package com.bjzs.skywalking.study.controller;

import com.bjzs.skywalking.study.domain.User;
import com.bjzs.skywalking.study.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:liuwenqing
 * @Date:2025/1/16 22:16
 * @Description:
 **/
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping(value = "/save")
    public User saveUser(@RequestBody User user) {
        userService.saveUser(user);
        return user;
    }
    @GetMapping(value = "/getUserById")
    public User getUserById(Integer id) {
        return userService.getUserById(id);
    }
    @GetMapping(value = "/getAllUsers")
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }
    @GetMapping(value = "/getUserByName")
    public User getUserByName(String name) {
        return userService.getUserByName(name);
    }
    @PostMapping(value = "/updateUser")
    public void updateUser(@RequestBody User user) {
        userService.updateUser(user);
    }
    @GetMapping(value = "/deleteUser/{id}")
    public void deleteUser(@PathVariable("id") Integer id) {
        userService.deleteUser(id);
    }

}
